<template>
  <div >
    <el-dialog
      v-model="openUp"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :destroy-on-close="true"
      @close = "share_cancel()"
      width="50%"
    >
      <template #header>
        <div class="customerTitle2"><span class="ct">确认收货</span>
          <span class="title1" v-if="type == 2">
 注：对需求状态为已发出的需求可点击【确认收货】按钮，确认后所有子订单均已收货
        </span>
          <span class="title1" v-else-if="type == 4">
 注：对售后单状态为待确认的补发单可点击【确认收货】按钮，确认后补发单变更已完成
        </span>
          <span class="title1" v-else>
 注：可对订单状态为已发货的点击【确认收货】按钮，确认后，该订单确认收货。对所有子订单完成确认收货则需求/单据状态自动变为确认收货。
          </span>
        </div>
      </template>
      <div>

        <el-form
          label-width="105px"
          ref="formDate"
          :model="formList"
        >
          <el-form-item label="收货备注" prop="remark">
            <el-input v-model="formList.remark" />
          </el-form-item>
          <el-form-item label="签收单上传" prop="filter" class="upLoad" >
            <UploadFile style="width: 100%"  drag :fileList="fileList" ref="uploadFileRef" />
          </el-form-item>
        </el-form>
      </div>
      <template #footer>
        <span class="dialog-footer customerDialog3">
            <el-button @click="share_cancel()">取消</el-button>
          <el-button type="primary"  @click="share_save(formList)">提交</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import lodash from 'lodash'
import {ElMessage} from "element-plus";
import Button from "/@/views/vab/form/button.vue";
import {orderConfirmReceipt} from "/@/api/dms/order/confirm";
import {customerReceipt} from "/@/api/dms/customerOrder";
import {orderGroupReceipt} from "/@/api/dms/order/group";
import UploadFile from './UpLoadFile.vue'
import { getRefundReceiving } from "/@/api/dms/refund";
const openUp = ref<any>(false)
const formDate = ref(undefined)
const formList = ref({
  remark:'',
  filter:'',
})
const $emits = defineEmits(['addressSubmit','resettingClick'])
const fileList = ref<any>([])
const uploadFileRef = ref<any>(null)
const uid = ref<any>(undefined)
const type = ref<number>(1)
const share_save = lodash.debounce(async (va:any='')=>{
  const url = uploadFileRef.value!.list.map((item:any,index:any)=>{return {response:item.response ? item.response : item.url,name:item.name}})
  if(type.value == 1){
    orderConfirmReceipt({uid:uid.value,receipt_mark:va.remark,receipt_form_img:JSON.stringify(url)}).then((data:any)=>{
      if(data.code == 200){
        openUp.value = false
        formList.value = {
          remark:'',
          filter:'',
        }
        ElMessage.success(`提交成功`)
        $emits('addressSubmit',1)
      }
    })
  }else if(type.value == 2){
   /* console.log(uid.value,'uid.value');
    console.log(va.remark,'va.remark');
    console.log(uploadFileRef.value!.list.map((item:any,index:any)=>{return item.response ? item.response : item.url}),'va.filter');*/

    // console.log(JSON.stringify(url));
    customerReceipt({uid:uid.value,receipt_mark:va.remark,receipt_form_img:JSON.stringify(url)}).then((data:any)=>{
      if(data.code == 200){
        openUp.value = false
        formList.value = {
          remark:'',
          filter:'',
        }
        ElMessage.success(`提交成功`)
        $emits('addressSubmit',1)
      }
    })
  }else if(type.value == 3){
    orderGroupReceipt({uid:uid.value,receipt_mark:va.remark,receipt_form_img:JSON.stringify(url)}).then((data:any)=>{
      if(data.code == 200){
        openUp.value = false
        formList.value = {
          remark:'',
          filter:'',
        }
        ElMessage.success(`提交成功`)
        $emits('addressSubmit',1)
      }
    })
  }else if(type.value == 4){
    const url1 = uploadFileRef.value!.list.map((item:any,index:any)=>{return {path:item.response ? item.response : item.url,name:item.name}})
    getRefundReceiving({uid:uid.value,receiving_remark:va.remark,receiving_path: url1}).then((data:any)=>{
      if(data.code == 200){
        openUp.value = false
        formList.value = {
          remark:'',
          filter:'',
        }
        ElMessage.success(`提交成功`)
        $emits('addressSubmit',1)
      }
    })
  }

},500)
const share_cancel = (formEl:any='')=>{
  openUp.value= false
  formList.value = {
    remark:'',
    filter:'',
  }
}
defineExpose(
  {
    openUp,
    uid,
    type,
  }
)
</script>

<style lang="scss" scoped>
@import "../../index";
.upLoad{
  :deep(){
    .el-upload-list{
      width: 100%;
    }
    .el-form-item__content{
      line-height: 16px;
    }
  }
}
</style>
